from itertools import product

# ○ 获取URL：response.url
# ○ 获取响应状态码：response.status_code
# ○ 获取Cookie：response.cookies
# ○ 获取响应头：response.headers
# ○ 获取响应头字符编码：response.encoding
# ○ 获取响应时间：response.elapsed.microseconds
# ○ 获取响应体：
# ■ 文本格式：response.text
# ■ 二进制格式: response.content
# ■ json格式：response.json()
import requests

# 用户端登录
Userlogin = requests.post(url="http://120.26.9.110:8899/api/login",
                          headers={"Content-Type": "application/json"},
                          json={
                              "account": "17640222026",
                              "password": "Aa123456!"
                          })
ftoken = Userlogin.json()["data"]["token"]
print(Userlogin.json())
# 用户端搜索商品
searchcommodity = requests.get(url="http://120.26.9.110:8899/api/products?keyword=%E6%89%8B%E6%9C%BA&page=1&limit=8",
                               headers={"Content-Type": "application/json"},
                               json={})
productID = searchcommodity.json()["data"][0]["id"]
print(searchcommodity.json())
# 用户端_添加购物车
add = requests.post(url="http://120.26.9.110:8899/api/cart/add",
                    headers={"Content-Type": "application/json",
                             "Authori-Zation": f"Bearer {ftoken}"},
                    json={"productId": productID, "cartNum": 1, "new": 0, "uniqueId": "1af59dc2", "virtual_type": 0})
cartID = add.json()["data"]["cartId"]
print(type(cartID))
print(add.json())
# 用户端_购物车内点击立即下单（确认订单）
confirm = requests.post(url="http://120.26.9.110:8899/api/order/confirm", headers={"Content-Type": "application/json",
                                                                                   "Authori-Zation": f"Bearer {ftoken}"},
                        json={"cartId": f"{cartID}", "new": 0, "addressId": 0})
print(confirm.json())
orderKey = confirm.json()["data"]["orderKey"]
# 用户端_点击立即支付（创建订单）
create = requests.post(url=f"http://120.26.9.110:8899/api/order/create/{orderKey}",
                       headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {ftoken}"},
                       json={"real_name": "za", "phone": "17640222026", "addressId": 1, "formId": "", "couponId": 0,
                             "payType": "yue", "useIntegral": "false", "bargainId": 0, "combinationId": 0,
                             "discountId": "null", "pinkId": 0, "advanceId": 0, "seckill_id": 0, "mark": "",
                             "from": "weixinh5", "shipping_type": 1, "new": 0, "invoice_id": "",
                             "quitUrl": "http://120.26.9.110/pages/order_pay_status/index?&type=3&totalPrice=4099"})
orderID = create.json()["data"]["result"]["orderId"]
print(create.json())
# 管理端_后台登录
Adminlogin = requests.post(url="http://120.26.9.110:8899/adminapi/login", headers={"Content-Type": "application/json"},
                           json={"account": "admin", "pwd": "Aa123456!", "imgcode": "pucx"})
mtoken = Adminlogin.json()["data"]["token"]
# 管理端_后台订单列表查询
orderList = requests.get(
    url=f"http://120.26.9.110:8899/adminapi/order/list?page=1&limit=10&status=&pay_type=&data=&real_name={orderID}&field_key=all&type=",
    headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {mtoken}"})
ID = orderList.json()["data"]["data"][0]["id"]
print(orderList.json())
# 管理端_点击提交发货
delivery = requests.put(url=f"http://120.26.9.110:8899/adminapi/order/delivery/{ID}",
                        headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {mtoken}"},
                        json={"type": "1", "express_record_type": "1", "delivery_name": "顺丰快运",
                               "delivery_id": "1111", "express_temp_id": "", "to_name": "", "to_tel": "", "to_addr": "",
                               "sh_delivery": "", "fictitious_content": "", "id": "", "to_add": "",
                               "export_open": "true", "delivery_code": "shunfengkuaiyun"})
print(delivery.json())
# 用户端_点击订单详情（订单详情）
detail =requests.get(url= f"http://120.26.9.110:8899/api/order/detail/{orderID}",
                    headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {ftoken}"})
Unique = detail.json()["data"]["cartInfo"][0]["unique"]
print(type(Unique))
print(detail.json())
# 用户端_点击确认收货
receipt =requests.post(url="http://120.26.9.110:8899/api/order/take",
                       headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {ftoken}"},
                       json={"uni":f"{orderID}"})
print(receipt.json())
# 用户端_点击立即评价
comment = requests.post(url="http://120.26.9.110:8899/api/order/comment",
                        headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {ftoken}"},
                        json={"comment":"111","product_score":5,"service_score":5,"pics":[],"unique":Unique})
print(comment.json())
# 用户端_删除订单
Userdel = requests.post(url="http://120.26.9.110:8899/api/order/del",
                       headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {ftoken}"},
                       json={"uni":orderID})
print(Userdel.json())
# 管理台_删除订单
Admindel =requests.delete(url=f"http://120.26.9.110:8899/adminapi/order/del/{ID}",
                        headers={"Content-Type": "application/json", "Authori-Zation": f"Bearer {mtoken}"})
print(Admindel.json())
